package com.CoreryBlack.service.Impl;

import com.CoreryBlack.Mapper.StudentMapper;
import com.CoreryBlack.po.PageBean;
import com.CoreryBlack.po.Student;
import com.CoreryBlack.po.StudentQueryParam;
import com.CoreryBlack.service.StudentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description StudentServiceImpl
 * @Author CoreryBlack
 * @Date 2024-09-19
 */

@Component
public class StudentServiceImpl implements StudentService {
    public StudentServiceImpl() {
    }

    @Autowired
    private StudentMapper studentMapper;

    public PageBean list(StudentQueryParam studentQueryParam) {
        PageHelper.startPage(studentQueryParam.getPage(), studentQueryParam.getPageSize());

        Page page1 = studentMapper.list(studentQueryParam);

        return new PageBean(page1.getTotal(), page1.getResult());
    }


    @Transactional
    @Override
    public void deleteByIds(List<Integer> ids) {
        studentMapper.deleteByIds(ids);
    }

    @Override
    public void saveStudent(Student student) {
        studentMapper.saveStudent(student);
    }

    @Override
    public Student queryById(Integer id) {
       return studentMapper.queryById(id);
    }

    @Override
    public void updateStudent(Student student) {
        studentMapper.updateStudent(student);
    }

    @Override
    public void updateStudentScore(Integer id, Integer score) {
        studentMapper.updateStudentScore(id,score);
    }

    @Override
    public Student getInfo(Integer id) {
        return studentMapper.getInfo(id);
    }

}
